package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;



import com.burgeon.backend.EnterpriseWeChat.entity.VipFamily;
import com.burgeon.backend.Rest.base.RESTBase;
import org.apache.http.util.TextUtils;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class addFamilyInfo extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public addFamilyInfo(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String cardNo, VipFamily vipFamily) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(cardNo,vipFamily), url);
        System.err.println("str="+str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");

        if (!"0".equals(code)) {
            throw new Exception(message);
        }
        String objectid = new JSONArray(str).getJSONObject(0).getString("objectid");

        return objectid;
    }

    private MultiValueMap Data(String cardNo, VipFamily vipFamily) {

        HashMap params = new HashMap();
        params.put("'C_VIP_ID__CARDNO'","'"+cardNo+"'");
        params.put("'CALL_TYPE'","'"+vipFamily.getCallType()+"'");
        params.put("'NAME'","'"+vipFamily.getName()+"'");
        params.put("'BIRTHDAY'","'"+vipFamily.getBirthday()+"'");
        if (!TextUtils.isEmpty(vipFamily.getDescription())) {
            params.put("'DESCRIPTION'","'"+vipFamily.getDescription()+"'");
        }

        params.put("table", "APP_FAMILY_INFORMATION");//表名

        return DATA("ObjectCreate", params, account, password);
    }


    public static void main(String[] args) {
        addFamilyInfo g = new addFamilyInfo("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            VipFamily vipFamily = new VipFamily();
            vipFamily.setCallType("妻子");
            vipFamily.setName("测");
            vipFamily.setBirthday("20201214");
            vipFamily.setDescription("测试");
            g.getData("13643111382",vipFamily);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
